package at.ltasat.classifier;

import java.util.Iterator;

public final class ClazzManager<D> implements Iterable<Clazz<D>> {

	private Clazz<?>[] classes;

	public ClazzManager(D[] datas) {
		classes = new Clazz<?>[datas.length];
		int id = 0;
		for (D data : datas) {
			classes[id] = new Clazz<D>(id, data);
			id++;
		}
	}

	public int size() {
		return classes.length;
	}

	@SuppressWarnings("unchecked")
	public Clazz<D> get(int index) {
		return (Clazz<D>) classes[index];
	}

	@Override
	public Iterator<Clazz<D>> iterator() {
		return new Iterator<Clazz<D>>() {

			private int index;

			{
				index = 0;
			}

			@Override
			public boolean hasNext() {
				return index < classes.length;
			}

			@Override
			public Clazz<D> next() {
				return get(index++);
			}

			@Override
			public void remove() {
				throw new UnsupportedOperationException();
			}
		};
	}

}
